package org.example.impl;

import org.example.clientEvent;

import java.io.InputStream;
import java.net.Socket;

public class clientEventImpl implements Runnable{
    private Socket socket;
    private clientEvent ce;

    public clientEventImpl(Socket socket, clientEvent ce) {
        this.socket = socket;
        this.ce = ce;
    }

    @Override
    public void run() {
        while (true){
            synchronized (this){
                try {
                    ce.messagesOutEvent(socket.getOutputStream());
                    InputStream is = socket.getInputStream();
                    byte[] cache = new byte[is.available()];
                    is.read(cache);
                    if (cache.length>2){
                        ce.messagesEvent(cache);

                    }

                }catch (Exception e){e.printStackTrace();}
            }
        }
    }
}
